#ifndef GAMECONTROLLER_H
#define GAMECONTROLLER_H

#include <QObject>
#include <QVector>
#include <QTimer>
#include <random>

class GameController : public QObject
{
    Q_OBJECT

public:
    enum Direction { UP, DOWN, LEFT, RIGHT };
    
    explicit GameController(QObject *parent = nullptr);
    
    void startNewGame();
    void move(Direction direction);
    QVector<QVector<int>> getBoard() const { return board; }
    int getScore() const { return score; }

signals:
    void boardChanged();
    void gameOver();
    void scoreUpdated(int score);

private:
    void addRandomTile();
    bool isMovePossible() const;
    bool isGameWon() const;
    bool moveTiles(Direction direction);
    void mergeTiles(Direction direction);
    
    QVector<QVector<int>> board;
    int score;
    std::mt19937 rng;
};

#endif // GAMECONTROLLER_H